package com.neasho.neashoadminv1.infrastructure.exception

import com.neasho.neashoadminv1.infrastructure.domain.R
import org.springframework.web.bind.annotation.RestControllerAdvice

class BusinessException(val code: Int, message: String) : RuntimeException(message) {
    companion object {
        fun create(message: String): BusinessException {
            return BusinessException(BusinessCode.unknow.code, message)
        }
    }
}

@RestControllerAdvice
class BusinessExceptionHandler {
    @org.springframework.web.bind.annotation.ExceptionHandler(BusinessException::class)
    fun handleBusinessException(e: BusinessException): R<String> {
        return R.error(e.code, e.message ?: "未知错误")
    }
}